<?php

class MenuComponent extends Object {
	
	var $components = array('Session');
 
	function startup() {
 
		$userMenu = array();
		$generalMenu = array();
 
		//$generalMenu[__('Home', true)] = '/';
		$generalMenu[__('Почетна', true)] = '/';
		$generalMenu[__('Денес', true)] = '/public/tonight';
		$generalMenu[__('Настани', true)] = '/public/events';
		$generalMenu[__('Рагледај', true)] = '/public/objekts';
		$generalMenu[__('За Нас', true)] = '/pages/aboutus';
		$generalMenu[__('Контакт', true)] = '/pages/contact';
 
		if(!$this->Session->check('Auth.User')) {
						
			$userMenu[__('Најави се', true)] = '/users/login';
			
		}
		else {
			
			$user = $this->Session->read('Auth.User');
			
			$groupModel = ClassRegistry::init('Group');
				
			$params = array('conditions'=>array("Group.id"=>$user['group_id']));
			$group = $groupModel->find('first',$params);	
	
			$group_name = '';
			
			switch ($group['Group']['name']){
				case 'Clients': $group_name = 'clients'; break;
				case 'Administrators': $group_name = 'admins'; break;
				default: $this->redirect('/users/login');
			}
			
			
			
			$userMenu[__('Одјави се', true)] = '/users/logout';
			
			if($group_name == 'clients'){
				
				$userMenu[__('Настани', true)] = '/events';
				
			}
			
			if($group_name == 'admins'){
				
				$companySubMenu = array();
				$companySubMenu[__('Фирми листа', true)] = '/companies';
				$companySubMenu[__('Креирај нова', true)] = '/companies/create';
			
				$userMenu[__('Фирми', true)] = $companySubMenu;
				
				$objektSubMenu = array();
				$objektSubMenu[__('Објекти листа', true)] = '/objekts';
				
				$userMenu[__('Објекти', true)] = $objektSubMenu;
				
				
				$citiesSubMenu = array();
				$citiesSubMenu[__('Градови листа', true)] = '/cities';
				$citiesSubMenu[__('Креирај нов', true)] = '/cities/create';
				
				$userMenu[__('Градови', true)] = $citiesSubMenu;
			
			
				$usersSubMenu = array();
				$usersSubMenu[__('Users', true)] = '/users';
				$usersSubMenu[__('Create user', true)] = '/users/create';
				
				$userMenu[__('Users', true)] = $usersSubMenu;
				//$userMenu[__('Change', true)] = '/users/change';
			}
		}
 
		//sample child item
		//$parent = array();
		//$parent[__('Child', true)] = '/';
		//$generalMenu[__('Parent', true)] = $parent;
 
		$user = $this->Session->read('Auth.User');
 
 
		//menus arra
		$menus = array();
		$menus[__('General', true)] = $generalMenu;
		$menus[__('User', true)] = $userMenu;
 
		$this->Session->write('Menu.main', $menus);
 
	}
}
